﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;

namespace TinyCinema.Data
{
    public class Feature : Execution
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public Feature(string _ID)
        {
            ID = _ID;
            PutTableIntoDataSet(Tables.Feature);
            var tbl = ds.Tables[Tables.Feature];
            var Row = tbl.Select(FeatureTable.ID + "='" + ID + "'")[0];
            Name = Row[FeatureTable.Name] as string;
            Description = Row[FeatureTable.Description] as string;
        }
        public void Save()
        {
            PutTableIntoDataSet(Tables.Feature);
            var tbl = ds.Tables[Tables.Feature];
            var Row = tbl.Select(FeatureTable.ID + "='" + ID + "'")[0];
            Row[FeatureTable.Name] = Name;
            Row[FeatureTable.Description] = Description;
            SaveCommand(Tables.Feature);
        }
        public static ObservableCollection<Feature> GetAllFeatures()
        {
            var lst = new ObservableCollection<Feature>();
            PutTableIntoDataSet(Tables.Feature);
            var tbl = ds.Tables[Tables.Feature];
            var Rows = tbl.Select();
            foreach (var row in Rows)
                lst.Add(new Feature(row[FeatureTable.ID] as String));
            return lst;
        }
    }
}
